import {onMounted, reactive} from "plain-ui-composition";
import {iVisualData} from "../../packages/utils/types.base";
import {$http} from "../http";

export function useRemoveData() {
    const state = reactive({
        value: null as null | iVisualData
    })
    onMounted(async () => {
        const url = new URL(window.location.href)
        const code = url.searchParams.get('code')
        if (!!code) {
            state.value = JSON.parse((await $http.post('/cms/item', {id: code})).result.json)
        } else {
            state.value = {
                pages: [{
                    "name": "新页面",
                    "show": true,
                    "gutter": 2,
                    "widthRange": {
                        "start": 0,
                        "end": "max"
                    },
                    "design": {
                        "width": 960,
                        "minHeight": 750
                    },
                    "childrenData": [],
                    "style": {}
                }],
            }
        }
    })
    return state
}
